package com.heiyu.utils;

import com.alibaba.fastjson.JSON;
import com.heiyu.dao.CoinBaseInfoMapper;
import com.heiyu.entity.CoinBaseInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Component
public class CoinBaseInfoUtils {


        @Autowired
        private  CoinBaseInfoMapper coinBaseInfoMapper;

        public CoinBaseInfo get(String key){
            String info = null;//redisUtils.get(key);
            CoinBaseInfo baseInfo;
            if(StringUtils.isNoneBlank(info)){
                baseInfo = JSON.parseObject(info,CoinBaseInfo.class);
            }else{
                baseInfo = new CoinBaseInfo();
                baseInfo.setTargetId(key);
                List<CoinBaseInfo> list = coinBaseInfoMapper.selectList(baseInfo);
                if(!CollectionUtils.isEmpty(list)){
                    baseInfo = list.get(0);
                    //redisUtils.set(key,JSON.toJSONString(baseInfo),86400);
                }else{
                    baseInfo = null;
                }
            }
            return baseInfo;
        }

}
